{extend name="layout" /} {block name="body"} <div class="row">
	<div class="col-lg-12">
		<div class="card">
			<div class="card-body">
				<div id="toolbar" class="toolbar-btn-action">
					<button type="button" data-toggle="modal" data-target="#exampleModal"
						class="btn btn-label btn-primary m-r-5">
						<label><i class="mdi mdi-plus" aria-hidden="true"></i></label>添加软件 </button>
					<button id="btn_delete" type="button" class="btn btn-label btn-danger">
						<label><i class="mdi mdi-window-close" aria-hidden="true"></i></label>删除 </button>
					<button id="btn_stateapp" type="button" class="btn btn-success"> 审核通过 </button>
					<button id="btn_stateallapp" type="button" class="btn btn-success"> 全部审核通过 </button>
				</div>
				<div class="input-group mb-3">
					<div class="form-group mb-2 mr-2">
						<input class="form-control" type="text" name="searchappname" id="searchappname"
							placeholder="请输入软件名..">
					</div>
					<div class="input-group-append">
						<a class="btn btn-default mb-2 mr-2" id="search_btn" href="#!"><i class="mdi mdi-magnify"></i>
							搜索</a>
					</div>
				</div>
				<table id="tb_departments"></table>
			</div>
		</div>
	</div>
	<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
		aria-hidden="true">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<h6 class="modal-title" id="exampleModalLabel">新增软件</h6>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<div class="form-group">
						<label for="appname">软件名称</label>
						<input type="text" class="form-control" id="appname" placeholder="请输入软件名称">
					</div>
					<div class="form-group file-apkgroup">
						<label for="appdownurl">上传软件</label>
						<div class="input-group">
							<input type="text" id="appdownurl" class="form-control file-apkvalue" name="appdownurl"
								placeholder="请输入软件链接地址">
							<input type="file" accept=".apk" style="display: none">
							<div class="input-group-btn">
								<button class="btn btn-default file-apk" type="button">上传软件</button>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label for="apppage">软件包名</label>
						<input type="text" class="form-control" id="apppage" placeholder="请输入软件包名,如com.yuncheng.ruanher">
					</div>
					<div class="form-group">
						<label for="appbb">软件版本</label>
						<input type="text" class="form-control" id="appbb" placeholder="请输入软件版本号,如1.0.0">
					</div>
					<div class="form-group">
						<label for="appdata">软件大小</label>
						<input type="text" class="form-control" id="appdata" placeholder="请输入软件大小,如12.3">
					</div>
					<div class="form-group">
						<label for="appmsg">软件介绍</label>
						<textarea class="form-control" id="appmsg" rows="3"   placeholder="请输入软件介绍"></textarea>
					</div>	
					<div class="form-group">
						<label for="appuser">软件作者</label>
						<input type="text" class="form-control" id="appuser" placeholder="请输入软件作者账号..">
					</div>
					<div class="form-group file-group">
						<label for="appicon">软件图标</label>
						<div class="input-group">
							<input type="text" id="appicon" class="form-control file-value" name="appicon"
								placeholder="请输入软件图标链接地址">
							<input type="file" accept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none">
							<div class="input-group-btn">
								<button class="btn btn-default file-browser" type="button">上传图标</button>
							</div>
						</div>
					</div>
					<div class="form-group file-group">
						<label for="apphenfu">软件横幅图</label>
						<div class="input-group">
							<input type="text" id="apphenfu" class="form-control file-value" name="apphenfu"
								placeholder="请输入软件横幅图链接地址">
							<input type="file" accept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none">
							<div class="input-group-btn">
								<button class="btn btn-default file-browser" type="button">上传横幅</button>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label for="appsortid">软件分类</label>
						<select class="form-control" id="appsortid"> 
						{foreach :query('appdownsort') as $key=>$value }
							<option value="{$value['id']}">{$value["sortname"]}(分类ID:{$value['id']})</option> 
						{/foreach}
						</select>
					</div>
					<div class="form-group">
						<label for="apptag">软件标签</label>
						<input type="text" class="form-control" id="apptag" placeholder="请输入软件标签名称,用英文;分割">
					</div>
					<div class="form-group file-groups">
					  <label for="appsce">软件截图</label>
					  <div class="js-upload-image">
						<ul id="file_list_more_pic" class="list-inline lyear-uploads-pic">							
						</ul>
						<input type="hidden" type="text" id="appsce" class="form-control file-values" name="appsce"
							placeholder="请输入软件截图链接地址">
						<button class="btn btn-success file-browsers" type="button">上传截图</button>
					    <input type="file" accept=".png,.jpg,.jpeg,.bmp,.gif" style="display: none">					    				    
					  </div>
					</div>
					<div class="form-group">
						<label for="appmod">是否MOD版本</label>
						<select class="form-control" id="appmod">
							<option value="0">否</option>
							<option value="1" selected>是</option>
						</select>
					</div>
					<div class="form-group">
						<label for="appisvip">下载方式</label>
						<select class="form-control" id="appisvip">
							<option value="0">免费下载</option>
							<option value="1" selected>会员下载</option>
						</select>
					</div>
					<div class="form-group">
						<label for="apptop">是否精选</label>
						<select class="form-control" id="apptop">
							<option value="0" selected>否</option>
							<option value="1">是</option>
						</select>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-secondary" id="shutdown" data-dismiss="modal">关闭</button>
					<button type="button" id="add" class="btn btn-w-sm btn-primary">保存</button>
				</div>
			</div>
		</div>
	</div>
</div>
{/block} 
{block name="js"}

<script>
	$('#tb_departments').bootstrapTable({
		classes: 'table table-bordered table-hover table-striped',
		url: "{:url('appdown/getallapp')}",
		method: 'get',
		dataType: 'json',
		uniqueId: 'id',
		idField: 'id', // 每行的唯一标识字段
		toolbar: '#toolbar', // 工具按钮容器
		showColumns: true, // 是否显示所有的列
		showRefresh: true, // 是否显示刷新按钮
		pagination: true, // 是否显示分页
		sortOrder: "desc", // 排序方式
		queryParams: function(params) {
			var temp = {
				limit: params.limit, // 每页数据量
				page: (params.offset / params.limit) + 1,
				sort: params.sort, // 排序的列名
				sortOrder: params.order, // 排序方式'asc' 'desc'
				appname: $.trim($('#searchappname').val())
			};
			return temp;
		}, // 传递参数
		sidePagination: "server", // 分页方式：client客户端分页，server服务端分页
		pageNumber: 1, // 初始化加载第一页，默认第一页
		pageSize: 10, // 每页的记录行数
		pageList: [10, 25, 50, 100], // 可供选择的每页的行数
		// search: true,                      // 是否显示表格搜索，此搜索是客户端搜索
		showExport: true, // 是否显示导出按钮, 导出功能需要导出插件支持(tableexport.min.js)
		exportDataType: "all", // 导出数据类型, 'basic':当前页, 'all':所有数据, 'selected':选中的数据
		columns: [{
			field: 'example',
			checkbox: true // 是否显示复选框
		}, {
			field: 'id',
			title: 'id',
			sortable: true // 是否排序
		}, {
			field: 'appname',
			title: '软件名',
		}, {
			field: 'appicon',
			title: '软件图标',
			formatter: function(value, row, index) {
				value = "<img src='" + row.appicon +
					"' style='width:50px;height:50px;border-radius: 15px;'/>";
				return value;
			}
		}, {
			field: 'username',
			title: '软件作者'
		}, {
			field: 'sortname',
			title: '软件分类',
			sortable: true,
		}, {
			field: 'apptime',
			title: '更新时间',
			sortable: true,
		}, {
			field: 'appisvip',
			title: '下载方式',
			formatter: function(value, row, index) {
				var value = "";
				if (row.appisvip == 0) {
					value = '<span class="badge badge-success">免费下载</span>';
				} else {
					value = '<span class="badge badge-danger">会员下载</span>';
				}
				return value;
			}
		}, {
			field: 'apptop',
			title: '是否精选',
			formatter: function(value, row, index) {
				var value = "";
				if (row.apptop == 1) {
					value = '<span class="badge badge-success">是</span>';
				} else {
					value = '<span class="badge badge-danger">否</span>';
				}
				return value;
			}
		}, {
			field: 'apppost',
			title: '审核状态',
			formatter: function(value, row, index) {
				var value = "";
				if (row.apppost == 0) {
					value = '<span class="badge badge-danger">未审核</span>';
				} else if (row.apppost == 1) {
					value = '<span class="badge badge-success">已发布</span>';
				} else {
					value = '<span class="badge badge-info">违规</span>';
				}
				return value;
			}
		}, {
			field: 'operate',
			title: '操作',
			formatter: btnGroup, // 自定义方法
			events: {
				'click .edit-btn': function(event, value, row, index) {
					window.location.href = "{:url('/admin/appdown/editapp/id/" + row.id + "')}";
				},
				'click .del-btn': function(event, value, row, index) {
					deleteuser(row.id, row.appname);
				}
			}
		}],
		onLoadSuccess: function(data) {
			$("[data-toggle='tooltip']").tooltip();
		}
	});
	// 操作按钮
	function btnGroup() {
		let html =
			'<a href="#!" class="btn btn-xs btn-default m-r-5 edit-btn" title="编辑" data-toggle="tooltip"><i class="mdi mdi-pencil"></i></a>' +
			'<a href="#!" class="btn btn-xs btn-default del-btn" title="删除" data-toggle="tooltip"><i class="mdi mdi-window-close"></i></a>';
		return html;
	}

	function getnumber() {
		var selRows = $('#tb_departments').bootstrapTable("getSelections");
		if (selRows.length == 0) {
			notify.error("请至少选择一行");
			return false;
		}
		var postData = "";
		$.each(selRows, function(i) {
			postData += this.id;
			if (i < selRows.length - 1) {
				postData += ",";
			}
		});
		return postData;
	}
	//新增软件
	$("#add").click(function() {
		var l = $('#add').lyearloading({
			opacity: 0.2,
			spinnerSize: 'nm'
		});
		var appname = $.trim($("#appname").val());
		var appdownurl = $.trim($("#appdownurl").val());
		var apppage = $.trim($("#apppage").val());
		var appbb = $.trim($("#appbb").val());
		var appdata = $.trim($("#appdata").val());
		var appicon = $.trim($("#appicon").val());
		var apphenfu = $.trim($("#apphenfu").val());
		var appsortid = $.trim($("#appsortid").val());
		var apptag = $.trim($("#apptag").val());
		var appsce = $.trim($("#appsce").val());
		var appmod = $.trim($("#appmod").val());
		var appisvip = $.trim($("#appisvip").val());
		var apptop = $.trim($("#apptop").val());
		var appuser = $.trim($("#appuser").val());
		var appmsg = $.trim($("#appmsg").val());
		$.ajax({
			type: 'post',
			url: "{:url('appdown/addapp')}",
			data: {
				'appname': appname,
				'appdownurl': appdownurl,
				'apppage': apppage,
				'appbb': appbb,
				'appdata': appdata,
				'appicon': appicon,
				'apphenfu': apphenfu,
				'appsortid': appsortid,
				'apptag': apptag,
				'appsce': appsce,
				'appmod': appmod,
				'appisvip': appisvip,
				'apptop': apptop,
				'appuser': appuser,
				'appmsg':appmsg
			},
			dataType: "json",
			success: function(data) {
				l.destroy();
				if (data.code == 1) {
					notify.success(data.msg);
					$("#exampleModal").modal('hide');
					$('#tb_departments').bootstrapTable('refresh');
				} else {
					notify.error(data.msg);
					$("#exampleModal").modal('hide');
				}
			},
			error: function() {
				l.destroy();
				notify.error("系统错误");
			}
		})
	});
	//审核选中软件
	$("#btn_stateapp").click(function() {
		var l = $('body').lyearloading({
			opacity: 0.2,
			spinnerSize: 'lg',
			spinnerText: '后台处理中，请稍后...',
			textColorClass: 'text-info',
			spinnerColorClass: 'text-info'
		});
		var getnum = getnumber();
		//console.log(getnum);
		if (getnum == false) {
			l.destroy();
			return false;
		}
		$.ajax({
			type: "POST",
			url: "{:url('appdown/stateapp')}",
			data: {
				id: getnum
			},
			dataType: "json",
			success: function(data) {
				l.destroy();
				if (data.code == 0) {
					notify.error(data.msg);
				} else {
					notify.success(data.msg);
				}
				$('#tb_departments').bootstrapTable('refresh');
			},
			error: function() {
				l.destroy();
				notify.error("系统错误");
			}
		});
	});
	//一键审核所有软件
	$("#btn_stateallapp").click(function() {
		var l = $('body').lyearloading({
			opacity: 0.2,
			spinnerSize: 'lg',
			spinnerText: '后台处理中，请稍后...',
			textColorClass: 'text-info',
			spinnerColorClass: 'text-info'
		});
		$.ajax({
			type: "POST",
			url: "{:url('appdown/stateallapp')}",
			data: {},
			dataType: "json",
			success: function(data) {
				l.destroy();
				if (data.code == 0) {
					notify.error(data.msg);
				} else {
					notify.success(data.msg);
				}
				console.log(data);
				$('#tb_departments').bootstrapTable('refresh');
			},
			error: function() {
				l.destroy();
				notify.error("系统错误");
			}
		});
	});
	$("#search_btn").click(function() {
		$('#tb_departments').bootstrapTable('refresh');
	})
	//单个删除软件
	function deleteuser(id, appname) {
		$.confirm({
			title: '确认删除',
			content: "确定删除软件《" + appname + "》?",
			autoClose: 'cancelAction|10000',
			escapeKey: 'cancelAction',
			buttons: {
				confirm: {
					btnClass: 'btn-red',
					text: '删除软件《' + appname + '》',
					action: function() {
						var l = $('body').lyearloading({
							opacity: 0.2,
							spinnerSize: 'lg',
							spinnerText: '后台处理中，请稍后...',
							textColorClass: 'text-info',
							spinnerColorClass: 'text-info'
						});
						$.ajax({
							type: "POST",
							url: "{:url('appdown/deleteapp')}",
							data: {
								id: id,
							},
							dataType: "json",
							success: function(data) {
								l.destroy();
								if (data.code == 0) {
									notify.error(data.msg);
								} else {
									notify.success(data.msg);
								}
								$('#tb_departments').bootstrapTable('refresh');
							},
							error: function() {
								l.destroy();
								notify.error("系统错误");
							}
						})
					}
				},
				cancelAction: {
					text: '取消',
					action: function() {}
				}
			}
		});
	}
	//批量删除软件
	$("#btn_delete").click(function() {
		var l = $('body').lyearloading({
			opacity: 0.2,
			spinnerSize: 'lg',
			spinnerText: '后台处理中，请稍后...',
			textColorClass: 'text-info',
			spinnerColorClass: 'text-info'
		});
		var getnum = getnumber();
		//console.log(getnum);
		if (getnum == false) {
			l.destroy();
			return false;
		}
		$.ajax({
			type: "POST",
			url: "{:url('appdown/deleteapp')}",
			data: {
				id: getnum
			},
			dataType: "json",
			success: function(data) {
				l.destroy();
				if (data.code == 0) {
					notify.error(data.msg);
				} else {
					notify.success(data.msg);
				}
				$('#tb_departments').bootstrapTable('refresh');
			},
			error: function() {
				l.destroy();
				notify.error("系统错误");
			}
		});
	});	
</script> 
{/block}
